package mutsumimod.cards.copy;

import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import mutsumimod.cards.BaseCard;
import mutsumimod.character.Mutsumi;
import mutsumimod.util.CardStats;
import mutsumimod.util.tags.CustomTags;

import java.util.ArrayList;

public class ONeiGai extends BaseCard{
    public static final String ID = makeID(ONeiGai.class.getSimpleName());

    public static final CardStats info = new CardStats(
            Mutsumi.Meta.CARD_COLOR,
            CardType.SKILL,
            CardRarity.UNCOMMON,
            CardTarget.SELF,
            1
    );

    public ONeiGai() {
        super(ID, info);
        setAttr(0,0,0);
        setAttrUpg(0,0,0);
        originShouldCopyUse = true;
        tags.add(CustomTags.SELF_CARD);
        setShouldCopyUse(true);
    }

    @Override
    public void beforeCopy(){
        clearCopyCards();
        addCopyCards(getNeighborCards());
    }

    @Override
    public void afterCopyUse(){
        upgradeBaseCost(++baseCost);
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {

    }

    public ArrayList<AbstractCard> getNeighborCards() {
        ArrayList<AbstractCard> neighborCards = new ArrayList<>();
        if (AbstractDungeon.player == null) {
            return neighborCards;
        }
        ArrayList<AbstractCard> hand = AbstractDungeon.player.hand.group;
        if (!hand.contains(this)) {
            return neighborCards;
        }
        int currentIndex = hand.indexOf(this);
        if (currentIndex > 0) {
            neighborCards.add(hand.get(currentIndex - 1));
        }
        if (currentIndex < hand.size() - 1) {
            neighborCards.add(hand.get(currentIndex + 1));
        }
        neighborCards.removeIf(c -> c.hasTag(CustomTags.SELF_CARD)||c.type.equals(AbstractCard.CardType.STATUS)||c.type.equals(AbstractCard.CardType.CURSE));
        return neighborCards;
    }

    @Override
    public AbstractCard makeCopy() { //Optional
        return new ONeiGai();
    }

    @Override
    public void upgrade(){
        if(!upgraded){
            upgradeName();
            upgradeBaseCost(--baseCost);
        }
    }
}